package com.ning.cloud.framework.security;


import com.ning.cloud.framework.security.dto.AuthUserDTO;

public class UserContext {

    //把构造函数私有化，外部不能new
    private UserContext() {

    }

    private static final ThreadLocal<AuthUserDTO> context = new ThreadLocal<AuthUserDTO>();

    /**
     * 存放用户信息
     *
     * @param user
     */
    public static void setAuthUser(AuthUserDTO user) {
        context.set(user);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    public static AuthUserDTO getAuthUser() {
        return context.get();
    }

    /**
     * 清除当前线程内引用，防止内存泄漏
     */
    public static void remove() {
        context.remove();
    }
}